package com.htandroid.htandroid.aty;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.ab.soap.AbSoapListener;
import com.ab.soap.AbSoapParams;
import com.ab.soap.AbSoapUtil;
import com.ab.util.AbDialogUtil;
import com.ab.util.AbToastUtil;
import com.ab.view.ioc.AbIocView;
import com.htandroid.htandroid.R;
import com.htandroid.htandroid.entity.UffjqgdList_detail;
import com.htandroid.htandroid.sys.Base_cggl_choose;
import com.htandroid.htandroid.sys.Basenvo;
import com.htandroid.htandroid.sys.InstorageURL;
import com.htandroid.htandroid.sys.User;
import com.htandroid.htandroid.tools.ToolLog;
import com.htandroid.htandroid.webservice.BuildCgglcgdXMLService;
import com.htandroid.htandroid.webservice.abXMLCgglqgdlist;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import static com.htandroid.htandroid.constance.ConstanceServer.BaseUrl_New;

/**
 * Created by lkp on 2015/11/29.
 */
public class Cggl_qg_index extends Base_cggl_choose {
    private ArrayList<UffjqgdList_detail> cgglqgdlist;
    private ArrayList<UffjqgdList_detail> isSelectList = new ArrayList<UffjqgdList_detail>();
    public String excelPath;
    public String imgPath;
    double amount = 0.00;
    ArrayList<Map<String, Object>> dataListForInit = null;

    @AbIocView(id = R.id.chooseall_cb)
    CheckBox chooseall_cb;
    //@AbIocView(id = R.id.tv_cgdorder)
    TextView tv_cgdorder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setAbContentView(R.layout.layout_cggl_qd);
        initview("请购生成订单");
        tv_cgdorder = (TextView) findViewById(R.id.tv_cgdorder);
        initview2();
        getdata(0);
    }

    public void btnClick(View v) {
        switch (v.getId()) {
            case R.id.tv_cgdorder:
                cgd_order();
                break;
        }
    }

    //初始化2
    @Override
    public void initview2() {
//        btn_share.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                newList = new ArrayList<MrqgdDjList>();
//                for (int i = 0; i < mrqgdlists.size(); i++) {
//                    if (sa.getIsSelected().get(i) == true) {
//                        newList.add(mrqgdlists.get(i));
//                    }
//                }
//                excelPath = getExcelDir() + File.separator + "请购叫货" + ".xls";
//                ExcelPurchase_cfqgqd cfqgqd = new ExcelPurchase_cfqgqd(Cggl_qg_index.this, excelPath, newList, listtype);
//                if (newList.size() == 0) {
//                    AbToastUtil.showToast(getApplicationContext(), "请选择要分享的数据");
//                } else {
//                    OnekeyShare oks = new OnekeyShare();
//                    oks.setTitle("请购叫货" + ".xls");
//                    oks.setShareContentCustomizeCallback(new ShareContentCustomizeCallback() {
//                        @Override
//                        public void onShare(Platform platform,
//                                            Platform.ShareParams paramsToShare) {
//                            // TODO Auto-generated method stub
//                            if (platform.getName().equals("Wechat")) {
//                                paramsToShare.setShareType(Platform.SHARE_FILE);
//                            }
//                        }
//                    });
//                    imgPath = getExcelDir() + File.separator + "excel.png";
//                    oks.setImagePath(imgPath);
//                    oks.setFilePath(excelPath);
//                    oks.show(getApplicationContext());
//                }
//            }
//        });

//        Intent intent = getIntent();// 创建Intent对象
//        //获取传递的对象参数
//        mrqgds = (MrqgdDjList) getIntent().getSerializableExtra("mrqgds");

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                linechoose("m", Integer.valueOf("" + id), adatperDataList);
                final View adapterView = view;
                final int i = position;
                ImageView edit_iv = (ImageView) adapterView.findViewById(R.id.edit_iv);
                edit_iv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //点击进入编辑状态
                        showMyDialog(i);
                    }
                });
                if (sa.getIsSelected().get(i) == true) {
//                if (adatperDataList.get(position).get("" + position).toString() == "true") {
                    isSelectList.add(cgglqgdlist.get(position));
                } else {
                    isSelectList.remove(cgglqgdlist.get(position));
                }
                amount = sa.sumAmount(adatperDataList);
                if (amount == 0.00) {
                    tv_cgdorder.setText("生成");
                } else {
                    tv_cgdorder.setText("生成（合计：" + amount + "元）");
                }
            }
        });

        chooseall_cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                // TODO Auto-generated method stub
                isSelectList = new ArrayList<UffjqgdList_detail>();
                // 遍历list的长度，将MyAdapter中的map值全部设为true
                for (int i = 0; i < adatperDataList.size(); i++) {
                    sa.getIsSelected().put(i, isChecked);
//                    adatperDataList.get(i).put("" + i, isChecked);
                    if (isChecked == true) {
                        isSelectList.add(cgglqgdlist.get(i));
//                        if (sa.getIamountUpdated().get(i) == null) {
//                            isSelectList.remove(cgglqgdlist.get(i));
//                        }
                    } else {
                        isSelectList.removeAll(isSelectList);
                    }
                }
                sa.notifyDataSetChanged();
                amount = sa.sumAmount(adatperDataList);
                if (amount == 0.00) {
                    tv_cgdorder.setText("生成");
                } else {
                    tv_cgdorder.setText("生成（合计：" + amount + "元）");
                }
            }
        });

        tv_cgdorder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cgd_order();
            }
        });
    }

    public void showMyDialog(final int position) {
        final View view = LayoutInflater.from(this).inflate(R.layout.basenvo_cgglqgdd, null);
        final EditText iprice_edit = (EditText) view.findViewById(R.id.iprice);
        final EditText iamount_edit = (EditText) view.findViewById(R.id.iamount);
        final EditText iquantity_edit = (EditText) view.findViewById(R.id.iquantity);
        EditText cdefine2_edit = (EditText) view.findViewById(R.id.cdefine2);
        EditText cdefine3_edit = (EditText) view.findViewById(R.id.cdefine3);
        String cdefine2 = cgglqgdlist.get(position).getS_cdefine2();
        String cdefine3 = cgglqgdlist.get(position).getS_cdefine3();
        final String iprice = Basenvo.space_add(Basenvo.customFormat("#####0.00##",
                cgglqgdlist.get(position).getIprice()), 12, 1);
        String iamount = Basenvo.space_add(Basenvo.customFormat("#####0.00##",
                cgglqgdlist.get(position).getIamount()), 12, 1);
        final String iquantity = Basenvo.space_add(Basenvo.customFormat("#####0.00##",
                cgglqgdlist.get(position).getIquantity()), 12, 1);
        iprice_edit.setText(iprice);
        iamount_edit.setText(iamount);
        iquantity_edit.setText(iquantity);
        cdefine2_edit.setText(cdefine2);
        cdefine3_edit.setText(cdefine3);

        iprice_edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                changeIprice(view, position);
                hintKey();
                return false;
            }
        });

        iprice_edit.setOnFocusChangeListener(new View.
                OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 此处为得到焦点时的处理内容
                    flag = "0";
                } else {
                    changeIprice(view, position);
                }
            }
        });

        iquantity_edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                changeIquantity(view, position);
                hintKey();
                return false;
            }
        });

        iquantity_edit.setOnFocusChangeListener(new View.
                OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 此处为得到焦点时的处理内容
                    flag = "2";
                } else {
                    changeIquantity(view, position);
                }
            }
        });

        iamount_edit.setOnFocusChangeListener(new View.
                OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 此处为得到焦点时的处理内容
                    flag = "1";
                } else {
                    changeIamount(view, position);
                }
            }
        });

        iamount_edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                changeIamount(view, position);
                hintKey();
                return false;
            }
        });

//        cdefine2_edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
//            @Override
//            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//                changeCdefine2(view, position);
//                //hintKey();
//                return false;
//            }
//        });

        cdefine2_edit.setOnFocusChangeListener(new View.
                OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 此处为得到焦点时的处理内容
                    flag = "3";
                } else {
                    changeCdefine2(view, position);
                }
            }
        });

//        cdefine3_edit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
//            @Override
//            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//                changeCdefine3(view, position);
//                hintKey();
//                return false;
//            }
//        });

        cdefine3_edit.setOnFocusChangeListener(new View.
                OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 此处为得到焦点时的处理内容
                    flag = "4";
                } else {
                    changeCdefine3(view, position);
                }
            }
        });

        AlertDialog dialog = new AlertDialog.Builder(Cggl_qg_index.this)
                //.setIcon(R.mipmap.icon)//设置标题的图片
                .setTitle("明细")//设置对话框的标题
                .setView(view)
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (flag == "0") {
                            changeIprice(view, position);
                        } else if (flag == "1") {
                            changeIamount(view, position);
                        } else if (flag == "2") {
                            changeIquantity(view, position);
                        } else if (flag == "3") {
                            changeCdefine2(view, position);
                        } else if (flag == "4") {
                            changeCdefine3(view, position);
                        }
                        hintKey();
                        dialog.dismiss();
                        amount = sa.sumAmount(adatperDataList);
                        if (amount == 0.00) {
                            tv_cgdorder.setText("生成");
                        } else {
                            tv_cgdorder.setText("生成（合计：" + amount + "元）");
                        }
                    }
                }).create();
        dialog.show();
    }

    private void changeIprice(View view, int position) {
        EditText iprice_edit = (EditText) view.findViewById(R.id.iprice);
        EditText iquantity_edit = (EditText) view.findViewById(R.id.iquantity);
        EditText iamount_edit = (EditText) view.findViewById(R.id.iamount);
        String changeIprice = iprice_edit.getText().toString();
        String iquantity = iquantity_edit.getText().toString();
        String iamount = "" + Double.parseDouble(changeIprice) * Double.parseDouble(iquantity);
        iamount_edit.setText(iamount);
        cgglqgdlist.get(position).setIprice(changeIprice);
        cgglqgdlist.get(position).setIamount(iamount);
        dataListForInit.get(position).put("iprice", changeIprice);
        dataListForInit.get(position).put("iamount", iamount);
        sa.notifyDataSetChanged();
    }

    private void changeIquantity(View view, int position) {
        EditText iprice_edit = (EditText) view.findViewById(R.id.iprice);
        EditText iquantity_edit = (EditText) view.findViewById(R.id.iquantity);
        EditText iamount_edit = (EditText) view.findViewById(R.id.iamount);
        String changeIquantity = iquantity_edit.getText().toString();
        String iprice = iprice_edit.getText().toString();
        String iamount = "" + Double.parseDouble(iprice) * Double.parseDouble(changeIquantity);
        iamount_edit.setText(iamount);
        cgglqgdlist.get(position).setIquantity(changeIquantity);
        cgglqgdlist.get(position).setIamount(iamount);
        dataListForInit.get(position).put("iquantity", changeIquantity);
        dataListForInit.get(position).put("iamount", iamount);
        sa.notifyDataSetChanged();
    }

    private void changeIamount(View view, int position) {
        EditText iprice_edit = (EditText) view.findViewById(R.id.iprice);
        EditText iquantity_edit = (EditText) view.findViewById(R.id.iquantity);
        EditText iamount_edit = (EditText) view.findViewById(R.id.iamount);
        String changeIamount = iamount_edit.getText().toString();
        String iquantity = iquantity_edit.getText().toString();
        String iprice = "" + Double.parseDouble(changeIamount) / Double.parseDouble(iquantity);
        iprice_edit.setText(iprice);
        cgglqgdlist.get(position).setIprice(iprice);
        cgglqgdlist.get(position).setIamount(changeIamount);
        dataListForInit.get(position).put("iprice", iprice);
        dataListForInit.get(position).put("iamount", changeIamount);
        sa.notifyDataSetChanged();
    }

    private void changeCdefine2(View view, int position) {
        EditText cdefine2_edit = (EditText) view.findViewById(R.id.cdefine2);
        String changeCdefine2 = cdefine2_edit.getText().toString();
        cdefine2_edit.setText(changeCdefine2);
        cgglqgdlist.get(position).setS_cdefine2(changeCdefine2);
        dataListForInit.get(position).put("data9", changeCdefine2);
        sa.notifyDataSetChanged();
    }

    private void changeCdefine3(View view, int position) {
        EditText cdefine3_edit = (EditText) view.findViewById(R.id.cdefine3);
        String changeCdefine3 = cdefine3_edit.getText().toString();
        cdefine3_edit.setText(changeCdefine3);
        cgglqgdlist.get(position).setS_cdefine3(changeCdefine3);
        dataListForInit.get(position).put("data10", changeCdefine3);
        sa.notifyDataSetChanged();
    }

    //获取数据
    @Override
    public void getdata(int page) {
        //参数
//        String urlString = "http://" + InstorageURL.SERVERURL
//                + BaseUrl_New;
//        String[] parms = {"user", "cacc_id", "iyear", "ddate", "ddate_dh", "cvencode"};
//        String[] vals = {User.nickName, (String) myApplication.getGs_ztid(), (String) myApplication.getGs_year(), mrqgds.getdDate(), mrqgds.getdDhDate(), mrqgds.getCvencode()};
//        //生成xml
//        BuildMrqgdXMLService service = new BuildMrqgdXMLService();
//        String xmlstring = service.buildXML("mrqgd_order", InstorageURL.NAME_SPACE, parms, vals, null, null);
//        mAbSoapUtil.xmlCall(urlString, InstorageURL.NAME_SPACE, "mrqgd_order", xmlstring, new AbSoapUtil.WebServiceCallBack() {
//            @Override
//            public void onSucced(String result) {
//                adatperDataList.clear();
//                ArrayList<Map<String, Object>> dataListForInit = new ArrayList<Map<String, Object>>();
//                if (result != null) {
//                    //解析xml文件,返回列表
//                    mrqgdlists = XMLMrqgdlist.paraseCommentInfors(result);
//
//                    for (int i = 0; i < mrqgdlists.size(); i++) {
//                        MrqgdDjList mrqgds1 = new MrqgdDjList();
//                        mrqgds1 = mrqgdlists.get(i);
//                        //                            aaa.add(item.getPropertyAsString(0));
//                        Map<String, Object> map = new HashMap<String, Object>();
//                        map.put("index", (i + 1));
//                        map.put("cdepname", mrqgds1.getCdepname());
//                        map.put("cinvname", mrqgds1.getcInvname());
//                        map.put("cinvstd", mrqgds1.getcInvstd());
//                        map.put("cinvunit", mrqgds1.getcInvm_unit());
//                        map.put("iquantity", mrqgds1.getiQuantity());
//                        map.put("cmemo", mrqgds1.getCmemo());
//                        map.put("iprice", mrqgds1.getIprice());
//                        dataListForInit.add(map);
//                        sa.getIsSelected().put(i, true);
//                    }
//                } else {
//                    AbToastUtil.showToast(getApplicationContext(), R.string.sqlerrormsg);
//                }
//                toolDataProvider.initData(dataListForInit);
//                loadList();
//                //mHandler.sendEmptyMessage(LIST_GET_FIRST_PAGE); //加载完毕发送指令显示第一页
//                //swipeRefreshLayout.setRefreshing(false);
//            }
//
//            @Override
//            public void onFailure(String result) {
//                AbToastUtil.showToast(getApplicationContext(), R.string.sqlerrormsg);
//                //swipeRefreshLayout.setRefreshing(false);
//            }
//        });

        String nameSpace = "http://service.test.com";
        String methodName = "cggl_qgd2dd_list";
        String urlString = "http://" + InstorageURL.SERVERURL + BaseUrl_New;
        AbSoapParams params = new AbSoapParams();
        params.put("arg0", User.uid);
        params.put("arg1", User.nickName);
        params.put("arg2", myApplication.getGs_ztid());
        params.put("arg3", myApplication.getGs_year());
        params.put("arg4", "0");
        mAbSoapUtil.call(urlString, nameSpace, methodName, params, new AbSoapListener() {
            //获取数据成功会调用这里
            @Override
            public void onSuccess(int statusCode, String content) {
                adatperDataList.clear();
                dataListForInit = new ArrayList<Map<String, Object>>();
                if (content != null) {
                    ToolLog.log(content);
                    cgglqgdlist = abXMLCgglqgdlist.paraseCommentInfors(content);
                    for (int i = 0; i < cgglqgdlist.size(); i++) {
                        UffjqgdList_detail cgglqgd = new UffjqgdList_detail();
                        cgglqgd = cgglqgdlist.get(i);
                        Map<String, Object> map = new HashMap<String, Object>();
                        map.put("index", (i + 1));
                        map.put("cinvcode", cgglqgd.getCinvcode());
                        map.put("cinvname", cgglqgd.getCinvname());
                        map.put("cinvstd", cgglqgd.getCinvstd());
                        map.put("cinvm_unit", cgglqgd.getCinvm_unit());
                        map.put("cvenname", cgglqgd.getCvenname());
                        map.put("cdepname", cgglqgd.getCdepname());
                        map.put("iprice", Basenvo.space_add(Basenvo.customFormat("#####0.00##", cgglqgd.getIprice()), 12, 1));
                        map.put("iquantity", Basenvo.space_add(Basenvo.customFormat("#####0.00##", cgglqgd.getIquantity()), 12, 0));
                        map.put("iamount", Basenvo.customFormat("#####0.00##", cgglqgd.getIamount()));
                        map.put("data1", "        请购数量：" + Basenvo.space_add(Basenvo.customFormat("#####0.00##", cgglqgd.getIquantity()), 12, 0));
                        map.put("data2", "        请购单价：" + Basenvo.space_add(Basenvo.customFormat("#####0.00##", cgglqgd.getIprice()), 12, 1));
                        map.put("data3", "               金额：" + Basenvo.customFormat("#####0.00##", cgglqgd.getIamount()));
                        map.put("data4", "要求到货日期：" + cgglqgd.getDdate_dh());
                        map.put("data5", "        请购日期：" + cgglqgd.getDdate());
                        map.put("data6", "请购单流水号：" + cgglqgd.getCvouchid());
                        map.put("data8", cgglqgd.getS_cdefine1());
                        map.put("data9", cgglqgd.getS_cdefine2());
                        map.put("data10", cgglqgd.getS_cdefine3());
                        map.put("" + i, "false");
                        dataListForInit.add(map);
                        sa.getIsSelected().put(i, false);
                    }
                    if (isSelectList.size() > 0) {
                        for (int j = 0; j < isSelectList.size(); j++) {
                            isSelectList.remove(j);
                            j--;
                        }
                    }
                } else {
                    AbToastUtil.showToast(Cggl_qg_index.this, R.string.sqlerrormsg);
                }
                toolDataProvider.initData(dataListForInit);
                loadList();
            }

            // 失败，调用
            @Override
            public void onFailure(int statusCode, String content,
                                  Throwable error) {
                AbDialogUtil.removeDialog(Cggl_qg_index.this);
                AbToastUtil.showToast(Cggl_qg_index.this, R.string.sqlerrormsg);
            }

            // 开始执行前
            @Override
            public void onStart() {
                //显示进度框
                AbDialogUtil.showProgressDialog(Cggl_qg_index.this, 0, "正在加载...");
            }

            // 完成后调用，失败，成功
            @Override
            public void onFinish() {
                //移除进度框
                AbDialogUtil.removeDialog(Cggl_qg_index.this);
            }
        });
    }

    public void cgd_order() {
        for (int i = 0; i < isSelectList.size(); i++) {
            if (Basenvo.space_add(Basenvo.customFormat("#####0.00##", isSelectList.get(i).getIprice()), 12, 1) == "0.00") {
                AbToastUtil.showToast(getApplicationContext(), "单价不能等于0！");
                return;
            } else if (Basenvo.space_add(Basenvo.customFormat("#####0.00##", isSelectList.get(i).getIquantity()), 12, 1) == "0.00") {
                AbToastUtil.showToast(getApplicationContext(), "数量不能等于0！");
                return;
            } else if (Basenvo.customFormat("#####0.00##", isSelectList.get(i).getIamount()) == "0.00") {
                AbToastUtil.showToast(getApplicationContext(), "金额不能等于0！");
                return;
            }
        }
        if (!(isSelectList.size() > 0)) {
            AbToastUtil.showToast(getApplicationContext(), "请选择数据！");
            return;
        }

        //参数
        String urlString = "http://" + InstorageURL.SERVERURL
                + BaseUrl_New;
        String[] parms = {"usercode", "username", "cacc_id", "iyear", "gs_sj"};
        String[] vals = {User.uid, User.nickName, (String) myApplication.getGs_ztid(), (String) myApplication.getGs_year(), myApplication.getGs_sj()};
        //生成xml
        BuildCgglcgdXMLService service = new BuildCgglcgdXMLService();
        String xmlstring = service.buildXML(isSelectList, "cggl_qgd2dd", InstorageURL.NAME_SPACE, parms, vals, "in" + vals.length);
        mAbSoapUtil.xmlCall(urlString, InstorageURL.NAME_SPACE, "cggl_qgd2dd", xmlstring, new AbSoapUtil.WebServiceCallBack() {
            @Override
            public void onSucced(String result) {
                if (result != null) {
                    String str = result.split("<ns1:out>")[1].split("</ns1:out>")[0];
                    if ("001".equals(str)) {
                        AbToastUtil.showToast(getApplicationContext(), "必须输入订单单据号！");
                    } else if ("002".equals(str)) {
                        AbToastUtil.showToast(getApplicationContext(), "不允许同时生成多张订单！");
                    } else if (str.contains("003")) {
                        String i = str.split(":")[1];
                        AbToastUtil.showToast(getApplicationContext(), "自定义项" + i + "必须输入！");
                    } else if ("004".equals(str)) {
                        AbToastUtil.showToast(getApplicationContext(), "列表中不允许生成数据中有不同供应商！");
                    } else if (str.contains("005")) {
                        String i = str.split(":")[1];
                        AbToastUtil.showToast(getApplicationContext(), "第" + i + "行存货已经生成订单或已被关闭，不能再次生成！");
                    } else if ("006".equals(str)) {
                        getdata(0);
                        AbToastUtil.showToast(getApplicationContext(), "请购单生成采购订单成功！");
                        tv_cgdorder.setText("生成");
                    }
                } else {
                    AbToastUtil.showToast(getApplicationContext(), R.string.sqlerrormsg);
                }
            }

            @Override
            public void onFailure(String result) {
                AbToastUtil.showToast(getApplicationContext(), R.string.sqlerrormsg);
                //swipeRefreshLayout.setRefreshing(false);
            }
        });
    }

    //删除
//    public void mrqgd_del(View v) {
//        mrqgdorderact("mrqgd_order_del", "删除定价");
//    }
//
//    //叫货
//    public void cgd_order(View v) {
//        mrqgdorderact("mrqgd_order_ok", "叫货");
//    }

    //删除和保存定价的动作函数
//    public void mrqgdorderact(String methodName, final String ctypetext) {
//        Boolean ischoose = false;
//        String iprice = "";
//        // 遍历list的长度，判断是否选中
//        HashMap<Integer, Boolean> selectlist = sa.getIsSelected();
//        //获取单价修改状态
//        HashMap<Integer, String> IpriceUpdated = sa.getIpriceUpdated();
//        //先判断存货是否选择,同时还要更改list中的选择标记
//        for (int i = 0; i < selectlist.size(); i++) {
//            MrqgdDjList mrqgd = (MrqgdDjList) mrqgdlists.get(i);
//            if (selectlist.get(i)) {
//                ischoose = true;
//                mrqgd.setBchecked("1");
//                iprice = IpriceUpdated.get(i);
//                mrqgd.setIprice(iprice);
//                mrqgd.setIamount(Basenvo.customFormat("#####0.00##", Double.valueOf(mrqgd.getiQuantity()) * Double.valueOf(iprice)));
//            } else {
//                mrqgd.setBchecked("0");
//            }
//        }
//        if (!ischoose) {
//            AbToastUtil.showToast(getApplicationContext(), "请选择需要" + ctypetext + "的存货");
//            return;
//        }
//        //刷新列表
//        String urlString = "http://" + InstorageURL.SERVERURL
//                + BaseUrl_New;
//        String[] parms = {"user", "cacc_id", "iyear", "ddate", "ddate_dh", "cvencode"};
//        String[] vals = {User.uid, (String) myApplication.getGs_ztid(), (String) myApplication.getGs_year(), mrqgds.getdDate(), mrqgds.getdDhDate(), mrqgds.getCvencode()};
//        String url = (String) myApplication.getGs_url();
//        //生成xml
//        BuildMrqgdXMLService service = new BuildMrqgdXMLService();
//        String xmlstring = service.buildXML(methodName, InstorageURL.NAME_SPACE, parms, vals, "in" + parms.length, mrqgdlists);
//        mAbSoapUtil.xmlCall(urlString, InstorageURL.NAME_SPACE, methodName, xmlstring, new AbSoapUtil.WebServiceCallBack() {
//            @Override
//            public void onSucced(String result) {
//                adatperDataList.clear();
//                ArrayList<Map<String, Object>> dataListForInit = new ArrayList<Map<String, Object>>();
//                if (result != null) {
//                    //解析xml文件,返回列表
//                    mrqgdlists = XMLMrqgdlist.paraseCommentInfors(result);
//                    AbToastUtil.showToast(getApplicationContext(), ctypetext + "成功!");
//                    if (mrqgdlists.size() > 0) {
//                        for (int i = 0; i < mrqgdlists.size(); i++) {
//                            MrqgdDjList mrqgds1 = new MrqgdDjList();
//                            mrqgds1 = mrqgdlists.get(i);
//                            //                            aaa.add(item.getPropertyAsString(0));
//                            Map<String, Object> map = new HashMap<String, Object>();
//                            map.put("index", (i + 1));
//                            map.put("cdepname", mrqgds1.getCdepname());
//                            map.put("cinvname", mrqgds1.getcInvname());
//                            map.put("cinvstd", mrqgds1.getcInvstd());
//                            map.put("cinvunit", mrqgds1.getcInvm_unit());
//                            map.put("iquantity", mrqgds1.getiQuantity());
//                            map.put("iprice", mrqgds1.getIprice());
//                            dataListForInit.add(map);
//                            sa.getIsSelected().put(i, true);
//                        }
//                        toolDataProvider.initData(dataListForInit);
//                        loadList();
//                        //mHandler.sendEmptyMessage(LIST_GET_FIRST_PAGE); //加载完毕发送指令显示第一页
//                        //swipeRefreshLayout.setRefreshing(false);
//                    } else {
//                        //增加一个全部删除或者全部叫货的判断
//                        setResult(R.layout.layout_mrqgd_orderdetail / 200000);  //设置返回结果
//                        finish();
//                    }
//                } else {
//                    AbToastUtil.showToast(getApplicationContext(), ctypetext + "失败!数据库错误");
//                }
//            }
//
//            @Override
//            public void onFailure(String result) {
//                AbToastUtil.showToast(getApplicationContext(), ctypetext + "失败!数据库错误");
//                //swipeRefreshLayout.setRefreshing(false);
//            }
//        });
//    }
}
